package log

import (
	"gitee.com/yysf_xin/dplog/pkg/ck"
	"gitee.com/yysf_xin/dplog/pkg/extracter/fex"
	"gitee.com/yysf_xin/dplog/pkg/extracter/java"
	"gitee.com/yysf_xin/dplog/pkg/slog"
	"gitee.com/yysf_xin/go-common/tools"
	"net/http"
	"os"
	"path"
	"time"
)

type UploadCk struct {
	dir  string
	c    *ck.Collect
	opt  *slog.Option
	java *java.Opt
}

func (u *UploadCk) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	d := r.URL.Query().Get("date")
	if d == "" {
		d = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
	}
	os.DirFS(path.Join(u.dir, d))
}

func NewUploadToCk(c *ck.Collect, dir string) *UploadCk {

	return nil
}

func (u *UploadCk) uploadFile(f, name string) {
	em := java.NewMybatis(u.c, []string{"org.apache.ibatis.logging.jdbc.BaseJdbcLogger"})
	c := slog.NewCollect(u.opt, fex.NewMakeLog(u.java, ""), em)
	r, err := slog.NewFileReader(f, c)
	if err != nil {
		tools.Log.Println(err)
		return
	}
	start := time.Now()
	r.Run()
	c.Flush()
	u.c.Flush()
	tools.Log.Println("耗时", time.Now().Sub(start), f, "总共", u.c.Total)
	u.c.Total = 0
}
